//
//  MovieShow.m
//  MINFOBBS
//
//  Created by juvid on 13-12-5.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "MovieShow.h"
#import "DetectionSystemVersion.h"
#import "UIColor+expanded.h"
@interface MovieShow ()

@end

@implementation MovieShow

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([[DetectionSystemVersion alloc]Version]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    [self BackButton];
    self.view.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    self.table.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
     [self.table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    NSArray *arr=[[self.arrReturn objectForKey:@"Properties"] objectForKey:@"Property"];
   
    
    self.labLocation.text=[self.arrReturn objectForKey:@"Title"];
   

//    NSLog(@"%@",self.arrReturn);
    [self setArr:arr];
    // Do any additional setup after loading the view from its nib.
}
-(void)BackButton{
    self.navigationItem.titleView=[DetectionSystemVersion SetBarTitle:@"百事搜"];
    [self.navigationItem setHidesBackButton:YES];
    UIButton *btnBack=[[DetectionSystemVersion alloc]BackButton];
    [btnBack addTarget:self action:@selector(BackReturn:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem=backItem;
    
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(void)setArr:(NSArray *)array{
    scheduleArr=[[NSArray alloc]init];
    NSString *str;
    for (int i=0; i<array.count; i++) {
        if ([[[array objectAtIndex:i]objectForKey:@"name"]isEqual:@"时间"]) {
            str=[[array objectAtIndex:i]objectForKey:@"text"];
        }
        else if([[[array objectAtIndex:i]objectForKey:@"name"]isEqual:@"电影"]){
             CGSize labSize=[DetectionSystemVersion String:[[array objectAtIndex:i]objectForKey:@"text"] Width:310 Font:16];
            
            self.latTitle.frame=CGRectMake((320-labSize.width)/2+15, self.latTitle.frame.origin.y, labSize.width, self.latTitle.frame.size.height);
            self.imgMovie.frame=CGRectMake((320-labSize.width)/2-15, self.imgMovie.frame.origin.y, self.imgMovie.frame.size.width, self.imgMovie.frame.size.height);
             self.latTitle.text=[[array objectAtIndex:i]objectForKey:@"text"];
        }
        else if([[[array objectAtIndex:i]objectForKey:@"name"]isEqual:@"城市"]){
             self.labCity.text=[[array objectAtIndex:i]objectForKey:@"text"];
        }
    }
     scheduleArr=[str componentsSeparatedByString:@","];
    [self.table reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //NSArray *list=[[[weatherIndex objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
    if(scheduleArr.count>0){
        return scheduleArr.count;
    }
    else{
        return 0;
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier=@"SchedulIdentifier";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor clearColor];
    }
    NSUInteger row=[indexPath row];
    NSString *dd=[scheduleArr objectAtIndex:row];
    cell.textLabel.text=dd;
    cell.imageView.image=[UIImage imageNamed:@"time1"];
    cell.textLabel.backgroundColor=[UIColor clearColor];
    if (indexPath.row%2==1) {
        UIView *vie=[[UIView alloc]init];
        vie.backgroundColor=[UIColor colorWithHexString:@"0xf3f3f3"];
        cell.backgroundView=vie;
    }
    else{
        cell.backgroundColor=[UIColor whiteColor];
    }    cell.textLabel.font=[UIFont systemFontOfSize:14];
    return cell;
}

#pragma mark 导航栏按钮事件
-(void)BackReturn:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
